﻿ using MyCourseManageProject.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;

namespace MyCourseManageProject.Dal.Service
{
    public class TeachersDal
    {
        /// <summary>
        /// 登录验证
        /// </summary>
        /// <param name="teacher"></param>
        /// <returns></returns>
        public Teachers TeacherLogin(Teachers teacher)
        {
            //1封装SQL语句
            string sql = string.Format(@"select TeacherName,TeacherId from Teachers where LoginAccount='{0}' and LoginPwd='{1}'", teacher.LoginAccount, teacher.LoginPwd);
            //2提交查询  (导入using System.Data.SqlClient;)
            SqlDataReader reader = SQLHelper.GetReader(sql);
            //3判断登录是否正确,如果正确封装讲师属性
            if (reader.Read())
            {
                teacher.TeacherId = Convert.ToInt32(reader["TeacherId"]);
                teacher.TeacherName = reader["TeacherName"].ToString();

            }
            else
            {
                teacher = null;//表示当前账号或密码不正确
            }
            reader.Close();
            return teacher;




        }
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="oldPwd"></param>
        /// <param name="newPwd1"></param>
        /// <returns></returns>
        public int UpdateTeachers(Teachers teacher)
        {
            string sql = string.Format("update Teachers set LoginPwd=@LoginPwd where TeacherId=@TeacherId");
            
            SqlParameter[] param = new SqlParameter[]{
                new SqlParameter("@LoginPwd",teacher.LoginPwd),
                new SqlParameter("@TeacherId",teacher.TeacherId)
            };
            //3执行SQL语句
            return SQLHelper.Update(sql, param);
        }


    }
}
